<template>
<!--  <h2>档案技术处理</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch">
      <el-form-item label="批次号" prop="batchNum">
        <el-input v-model="queryParams.batchNum" placeholder="请输入批次号" clearable style="width: 300px" maxlength="30"></el-input>
      </el-form-item>
      <el-form-item label="任务名称" prop="taskName">
        <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable style="width: 300px" maxlength="30"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button style="margin-left: 20px" type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" ref="refbut">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus"  @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" border :height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id"/>
      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="scope">
          <el-button type="text" @click="handleGearShifting(scope.row)" v-show="scope.row.taskStatus==1">调档</el-button>
          <el-button type="text" @click="handleFinish(scope.row)" v-show="scope.row.taskStatus==2">结束</el-button>
          <el-button type="text" @click="handleDelete(scope.row)" v-show="scope.row.taskStatus==1 || scope.row.taskStatus==3">删除</el-button>
          <el-button type="text" @click="handleStart(scope.row)" v-show="scope.row.taskStatus==1">开始</el-button>
          <el-button type="text" @click="handleView(scope.row)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="任务类型" prop="taskType" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>
            <span v-for="(i, idx) in taskTypeOption" :key="idx">
              {{ scope.row.taskType == i.value ? i.label : '' }}
            </span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="批次号" prop="batchNum" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="任务名称" prop="taskName" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="任务状态" prop="taskStatus" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>
            <span v-for="(i, idx) in taskStatusOption" :key="idx">
              {{ scope.row.taskStatus == i.value ? i.label : '' }}
            </span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="任务开始时间" prop="taskStart" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="任务结束时间" prop="taskEnd" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="任务负责人" prop="taskLeader" align="center" :show-overflow-tooltip="true"/>
      <el-table-column label="任务备注" prop="remark" align="center" :show-overflow-tooltip="true"/>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加/修改档案技术处理 -->

    <gearShifting v-if="open" :open="open" ref="dajsRef" :rowData="rowData" @closeDelDialog="closeDelDialog" @submitForm="submitForm" :isType="isType"></gearShifting>
  </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import {
  addDajs,
  deleteDajs,
  getBatchNumber, getDajsById,
  getTableList,
  updateDajs
} from "@/api/archive/warehouseManagement/technicalProcessing";
import GearShifting from "@/views/archive/warehouseManagement/technicalProcessing/gearShifting";

export default {
  name: "index",
  components: { GearShifting },
  mixins: [estimateTableHeight], // 混入方法
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNum: undefined,
        taskName: undefined
      },
      // 显示搜索条件
      showSearch: true,
      dataList: [],
      total: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 弹出层表单
      rowData: {},
      // 任务类型
      taskTypeOption: [
        { value: '3', label: '数字化'},
        { value: '4', label: '缩微'},
        { value: '5', label: '修复'},
        { value: '6', label: '保护技术处理'},
        // { value: '7', label: '其他情况'},
      ],
      // 任务状态
      taskStatusOption: [
        { value: 1, label: '未开始'},
        { value: 2, label: '进行中'},
        { value: 3, label: '已完成'},
      ],
      isType: ''
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getList() {
      this.loading = true
      getTableList(this.queryParams).then(res=>{
        this.loading = false
        this.dataList = res.rows
        this.total = res.total
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    table_index(index){
      return (this.queryParams.pageNum-1) * this.queryParams.pageSize + index + 1;
    },
    // 新增
    handleAdd() {
      this.rowData = {};
      getBatchNumber().then(response=>{
        this.rowData.batchNum = response.data.batchNumber
        if( response.data.batchNumber!=undefined){
          this.title = "新增"
        this.open = true
        this.isType = '0'
        }
       
      })
    },
    // 调档
    handleGearShifting(row) {
      getDajsById({
        id: row.id,
        sjType: '1',
      }).then(response=>{
        this.rowData = response.data
        this.title = "调档"
        this.open = true
        this.isType = '1'
      })
    },
    // 删除
    handleDelete(row) {
      var id = row.id
      this.$modal.confirm('是否确认删除任务名称为"' + row.taskName + '"的数据项？').then(function () {
        return deleteDajs({ids: [id]})
      }).then(response=>{
        this.$modal.msgSuccess('删除成功')
        this.getList()
      }).catch(() => { });
    },
    // 结束
    handleFinish(row) {
      this.$modal.confirm('是否确认结束任务名称为"' + row.taskName + '"的数据项？').then(function () {
        row.taskStatus = '3'
        return updateDajs(row)
      }).then(res=>{
        this.$modal.msgSuccess('任务结束')
        this.getList()
      }).catch(() => { });
    },
    // 开始
    handleStart(row) {
      this.$modal.confirm('是否确认开始任务名称为"' + row.taskName + '"的数据项？').then(function () {
        row.taskStatus = '2'
        return updateDajs(row)
      }).then(res=>{
        this.$modal.msgSuccess('任务开始')
        this.getList()
      }).catch(() => { });
    },
    // 详情
    handleView(row) {
      getDajsById({
        id: row.id,
        sjType: '1',
      }).then(response=>{
        this.rowData = response.data
        this.title = "详情"
        this.open = true
        this.isType = '2'
      })
    },

    submitForm() {
      this.open = false
      this.getList()
    },
    closeDelDialog() {
      this.open = false
    }
  }
}
</script>

<style  lang="scss" scoped>

</style>
